<?php
class tgyuan_adminControl extends skymvc{
	
	public function __construct(){
		parent::__construct();
	}
	
	public function onDefault(){
		$this->smarty->assign(array(
			"data"=>M("tgyuan_admin")->selectRow("shopid=".SHOPID) 
		));
		$this->smarty->display("tgyuan_admin/add.html");
	}
	
	public function onSave(){
		$data['adminname']=$adminname=post('adminname','h');
		
		if(post('password')){
				if(post('password')!=post('password2')) $this->goall("两次密码输入不一致",1);
				$data["salt"]=rand(1000,9999);
				$data["password"]=umd5(post("password","h").$data["salt"]);
				
		}
		$row=M("tgyuan_admin")->selectRow("adminname='".$adminname."'");
		
		if($row && $row['adminid']!=$_SESSION['sstgyuan_admin']['adminid']){
			$this->goall("账号已经存在",1);
		}
		$salt=rand(1000,9999);
		
		M("tgyuan_admin")->update($data,"adminid=".$_SESSION['sstgyuan_admin']['adminid']);
		$this->goall("修改成功",0);
	}
	
	public function onShop(){
		$data=M("tgyuan_area")->select(array(
			"where"=>" tgyid=".SHOPID
		));
		if($data){
			foreach($data as $k=>$v){
				$shopids[]=$v['shopid'];
			}
			$shops=M("ymdian")->getSHopByIds($shopids);
			foreach($data as $k=>$v){
				$shop=$shops[$v['shopid']];
				$v=$shop;
				$data[$k]=$v;
			}
		}
		$this->smarty->assign(array(
			"data"=>$data
		));
		
		$this->smarty->display("tgyuan_admin/shop.html");	
	}
	
	
}
?>